package com.ghsc.ghxc.jsb.ui.integral.view

import android.text.TextUtils
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import com.cn.appcore.ext.getCompatColor
import com.cn.appcore.ext.loge
import com.cn.appcore.ext.setSingleClickListener
import com.cn.appcore.ext.showToast
import com.flyco.roundview.RoundTextView
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ext.http.request
import com.ghsc.ghxc.jsb.ui.integral.bean.KuaiDiBean
import com.ghsc.ghxc.jsb.view.ConfirmCancelPopViiew
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.enums.PopupAnimation

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.integral.view
 * 类名：SubDeliveryPopViiew
 * 创建时间：2024/5/24 11:03
 * 创建人 @author： xiaolin
 * 描述 ：Todo...订单发货
 */
class SubDeliveryPopViiew  (context: FragmentActivity, title:String, oid:String, mList :MutableList<KuaiDiBean>, btnConfirm:(kdno:String,kdname:String)->Unit, btnCancel:()->Unit) : CenterPopupView(context) {
    private var btnConfirm: (kdno:String,kdName:String) -> Unit = btnConfirm
    private var btnCancel: () -> Unit = btnCancel
    private var oid=oid
    private var title=title
    private var mList=mList
    private val mContext = context
    override fun getImplLayoutId() = R.layout.pw_confirm_deliver
    var kdName:TextView?=null
    var kdno: EditText?=null


    override fun onCreate() {
        super.onCreate()
        findViewById<TextView>(R.id.tvTitle).text=title
        findViewById<TextView>(R.id.oid).text=oid
        kdName=findViewById(R.id.kdName)
        kdno=findViewById(R.id.kdno)
        findViewById<RoundTextView>(R.id.tvBtnConfirm).setOnClickListener {

            if(TextUtils.isEmpty(kdno!!.text.toString().trim())){
                showToast("请输入快递单号")
                return@setOnClickListener
            }
            if(TextUtils.isEmpty(kdName!!.text.toString().trim())){
                showToast("请选择快递公司")
                return@setOnClickListener
            }
            btnConfirm.invoke(kdno!!.text.toString().trim(),kdName!!.text.toString().trim())
            dismiss()
        }
        findViewById<TextView>(R.id.tvBtnCancel).setOnClickListener {
            btnCancel.invoke()
            dismiss()
        }

        findViewById<LinearLayout>(R.id.llBtnType).setSingleClickListener{
//            btnTypeList.invoke()
            XPopup.Builder(mContext)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter  )
                .customHostLifecycle(lifecycle)
                .dismissOnTouchOutside(true)
                .navigationBarColor(mContext.getCompatColor(R.color.bg_dark_color))
                .asCustom(
                    KuaiDiListPopupView(mContext,
                        mList,
                        tvBtnSub = {
                            loge("选择的是：${it}")
                            kdName!!.text=it
                        }
                    )
                ).show()
        }
    }
}

